Home |
| Latest | About | Random
# (class sneak peak) Do not worry about this much yet, just a sneak peak of an example of a class we can design. Here we make a custom `Dog` class. We will discuss this much more down the line. For now we will focus on using the `string` class (and `vector` class later). This is just to illustrate, a class is a data type that contains both - "data" (member variables), like `name`, and - "methods" (member functions), like `bark` and `bites`. ```cpp #include #include using namespace std; class Dog { private: string name; public: Dog(const char* _name): name(_name) {} Dog() : name("Wild dog") {} void bark() const { cout << name << " goes woof woof!\n"; } void bites(const Dog& another_dog) const { cout << name << " bites " << another_dog.name << "!\n"; } }; int main(){ Dog dog1 = "Biscuit"; Dog dog2 = "Coupon"; Dog dog3; dog1.bark(); dog2.bark(); dog3.bark(); dog3.bites(dog1); return 0; } ```